package com.avic.rong.course.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.avic.rong.BaseActivity;
import com.avic.rong.MainActivity;
import com.avic.rong.R;
import com.avic.rong.userOrder.MineFragmentEvent;
import com.avic.rong.userOrder.activity.OrderSearchActivity;
import com.avic.rong.userOrder.adapter.MineOrderViewPagerAdapter;
import com.flyco.tablayout.SlidingTabLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;

import butterknife.BindView;

public class PublishCardActivity extends BaseActivity {


    @BindView(R.id.tab_layout)
    SlidingTabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.iv_seach)
    ImageView ivSeach;
    @BindView(R.id.iv_order_select)
    ImageView ivOrderSelect;
    @BindView(R.id.ll_root)
    LinearLayout llRoot;
    @BindView(R.id.ll_title_bar)
    LinearLayout llTitleBar;
    private ArrayList<String> titleList = new ArrayList<>();
    private ArrayList<Fragment> fragmentList = new ArrayList<>();
    private final String[] mTitles = {"全部", "审核中", "对接中", "未通过", "已关闭"};
    private int order_state;
    private PopupWindow popupWindow;
    private boolean rotateStart = false;
    private String orderType = "全部";
    public static String ORDER_JUMP = "orderJump";
    public static String Fabuname = "";



    public static TextView tv_title;
    private String enterType;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_publish_list;
    }

    @Override
    protected void initView() {
        tv_title = findViewById(R.id.tv_title);
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        Fabuname=name;
        tvTitle.setText(name);
        ivOrderSelect.setVisibility(View.GONE);


        titleList.add("全部");
        titleList.add("审核中");
        titleList.add("对接中");
        titleList.add("未通过");
        titleList.add("已关闭");

        for (int i = 0; i < titleList.size(); i++) {
            PublishFragment mineOrderFragment = new PublishFragment();
            Bundle bundle = new Bundle();
            if (i == 0) {
                bundle.putString("ORDER_TYPE", "全部");
            } else if (i == 1) {
                bundle.putString("ORDER_TYPE", "审核中");
            } else if (i == 2) {
                bundle.putString("ORDER_TYPE", "对接中");
            } else if (i == 3) {
                bundle.putString("ORDER_TYPE", "未通过");
            } else if (i == 4) {
                bundle.putString("ORDER_TYPE", "已关闭");
            }
            mineOrderFragment.setArguments(bundle);
            fragmentList.add(mineOrderFragment);
        }

        MineOrderViewPagerAdapter mineOrderViewPagerAdapter = new MineOrderViewPagerAdapter(getSupportFragmentManager(), titleList, fragmentList);
        viewPager.setAdapter(mineOrderViewPagerAdapter);
        viewPager.setOffscreenPageLimit(4);
        tabLayout.setViewPager(viewPager, mTitles);
        //   1   审核中   2    对接中    3     未通过     4  已关闭
//        if (order_state != -1) {
//            if (order_state == 1) {
//                viewPager.setCurrentItem(1);
//            } else if (order_state == 2) {
//                viewPager.setCurrentItem(2);
//            } else if (order_state == 3) {
//                viewPager.setCurrentItem(3);
//            } else if (order_state == 4) {
//                viewPager.setCurrentItem(4);
//            }
//        }


    }


    @Override
    protected void addListener() {
        ivSeach.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PublishCardActivity.this, OrderSearchActivity.class);
                startActivity(intent);
            }
        });
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    finish();
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        for (int i = 0; i < titleList.size(); i++) {
            fragmentList.get(i).onActivityResult(requestCode, resultCode, data);
        }
    }


    @Subscribe

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
